package com.ynny.bean.Dao;

import com.ynny.bean.yyy.Score;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ScoreManage implements ScoreManagerimpl {

    @Override
    public void addScore(Score score) {
        String sql = "insert into score(number,chinese,english,math) values(?,?,?,?)";
        Object[] objects = {score.getNumber(),score.getChinese(),score.getEnglish(),score.getMath()};
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        jdbcTemplate.update(sql,objects);
        int num = jdbcTemplate.update(sql,objects);
        if (num<=0)
            System.out.println("添加失败");
    }

    @Override
    public void updateScore(String number) {

        String sql = "update score set chinese=?,english=?,math=? where number=?";
        if (number == null)
            System.out.println("输入错误");
        }

    }

    @Override
    public void queryScoreByNumber(String number) {
    String sql = "select * from score where number=?";
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    Score score = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<Score>(Score.class), number);
        System.out.println(score);
    }

    @Override
    public void queryAllScore() {

        String sql = "select * from score";
        List<Score> scores = new JdbcTemplate().query(sql, new BeanPropertyRowMapper<Score>(Score.class));
        for (Score score : scores) {
            System.out.println(score);
        }

    }
}
